app.controller("typeTemplateController",function (
    $scope,
    $controller,
    typeTemplateService,
    brandService,
    specificationService) {
    $controller("baseController",{$scope:$scope});

    $scope.list = [];
    $scope.searchEntity = {};
    $scope.entity = {customAttributeItems:[]};
    $scope.search = function (page,rows) {
        typeTemplateService.findPage(page,rows,$scope.searchEntity).then(function (result ) {
            $scope.pageModel.totalItems = result.data.total;
            $scope.list = result.data.rows;
        });
    }
    $scope.brandList = {
        data: []
    };
    $scope.specList = {
        data: []
    };
    $scope.findBrandList = function () {
        brandService.findBrandList().then(function (result) {
            $scope.brandList.data = result.data;
        })
    }


    $scope.findSpecList = function () {
        debugger;
        specificationService.findSpecList().then(function (result) {
            $scope.specList.data= result.data;
        })

    }
    $scope.save = function () {
        typeTemplateService.save($scope.entity).then(function (result) {
            if (result.data.success){
                $scope.reloadList();
            }else{
                alert(result.data.message);
            }
        })
    }
    $scope.findOne = function (id) {
        typeTemplateService.findOne(id).then(function (result) {
            $scope.entity = result.data;
            $scope.entity.brandIds = JSON.parse($scope.entity.brandIds);
            $scope.entity.specIds = JSON.parse($scope.entity.specIds);
            $scope.entity.customAttributeItems = JSON.parse($scope.entity.customAttributeItems);
        })
    }

})